package com.zyx.flink.realtime.utils;

import java.util.concurrent.*;

/**
 * @author zyx
 * @since 2021/6/11 20:01
 * desc: 线程池工具类
 */
public class ThreadPoolUtil {
    private static ExecutorService pool;
    public static ExecutorService getInstance(){
        if(pool == null){
            synchronized (ThreadPoolUtil.class){
                if(pool == null){
                    pool = new ThreadPoolExecutor(2,
                            8,
                            10000,
                            TimeUnit.MILLISECONDS,
                            new ArrayBlockingQueue<>(10),
                            Executors.defaultThreadFactory(),
                            new ThreadPoolExecutor.CallerRunsPolicy());
                }
            }
        }
        return pool;
    }
}
